﻿using AutomatedTestDataManagement.Models;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web.Mvc;

namespace AutomatedTestDataManagement.Controllers
{
    public class SuitesTestController : Controller
    {
        private ApplicationTestDataEntities db = new ApplicationTestDataEntities();

        //
        // GET: /SuitesTest/

        public ActionResult Index()
        {
            var testsuitetests = db.TestSuiteTests.Include(t => t.Test).Include(t => t.TestSuite);
            return View(testsuitetests.ToList());
        }

        //
        // GET: /SuitesTest/Details/5

        public ActionResult Details(int id = 0)
        {
            TestSuiteTest testsuitetest = db.TestSuiteTests.Find(id);
            if (testsuitetest == null)
            {
                return HttpNotFound();
            }
            return View(testsuitetest);
        }

        //
        // GET: /SuitesTest/Create

        public ActionResult Create(int suiteID = 0)
        {
            ViewBag.TestID = new SelectList(db.Tests, "TestID", "TestName");

            if (suiteID == 0)
            {
                ViewBag.SuiteID = new SelectList(db.TestSuites, "SuiteID", "SuiteName");
            }
            else
            {
                ViewBag.SuiteID = new SelectList(db.TestSuites, "SuiteID", "SuiteName", suiteID);
            }
            return View();
        }

        //
        // POST: /SuitesTest/Create

        [HttpPost]
        public ActionResult Create(TestSuiteTest testsuitetest)
        {
            if (ModelState.IsValid)
            {
                db.TestSuiteTests.Add(testsuitetest);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.TestID = new SelectList(db.Tests, "TestID", "TestName", testsuitetest.TestID);
            ViewBag.SuiteID = new SelectList(db.TestSuites, "SuiteID", "SuiteName", testsuitetest.SuiteID);
            return View(testsuitetest);
        }

        //
        // GET: /SuitesTest/Edit/5

        public ActionResult Edit(int id = 0)
        {
            TestSuiteTest testsuitetest = db.TestSuiteTests.Find(id);
            if (testsuitetest == null)
            {
                return HttpNotFound();
            }
            ViewBag.TestID = new SelectList(db.Tests, "TestID", "TestName", testsuitetest.TestID);
            ViewBag.SuiteID = new SelectList(db.TestSuites, "SuiteID", "SuiteName", testsuitetest.SuiteID);
            return View(testsuitetest);
        }

        //
        // POST: /SuitesTest/Edit/5

        [HttpPost]
        public ActionResult Edit(TestSuiteTest testsuitetest)
        {
            if (ModelState.IsValid)
            {
                db.Entry(testsuitetest).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.TestID = new SelectList(db.Tests, "TestID", "TestName", testsuitetest.TestID);
            ViewBag.SuiteID = new SelectList(db.TestSuites, "SuiteID", "SuiteName", testsuitetest.SuiteID);
            return View(testsuitetest);
        }

        //
        // GET: /SuitesTest/Delete/5

        public ActionResult Delete(int id = 0)
        {
            TestSuiteTest testsuitetest = db.TestSuiteTests.Find(id);
            if (testsuitetest == null)
            {
                return HttpNotFound();
            }
            return View(testsuitetest);
        }

        //
        // POST: /SuitesTest/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            TestSuiteTest testsuitetest = db.TestSuiteTests.Find(id);
            db.TestSuiteTests.Remove(testsuitetest);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}